package groep1.filter;

import groep1.ObjectRepresentation;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import bluej.debugmgr.inspector.FieldInfo;

public class AndFilter extends LogicalFilter {

	public AndFilter(String regex1, String regex2, HashSet<ObjectRepresentation> objects) {
		super(regex1, regex2, objects);
	}

	@Override
	public HashMap<String, List<FieldInfo>> join() {
		HashMap<String, List<FieldInfo>> map1 = super.side1.join();
		HashMap<String, List<FieldInfo>> map2 = super.side2.join();
		for (String key : map1.keySet()) {
			if (!map2.containsKey(key)) {
				map1.remove(key);
			} else { // obj zit in allebei, enkel velden overhouden die beide obj hebben
				List<FieldInfo> list1 = map1.get(key);
				List<FieldInfo> list2 = map2.get(key);
				Iterator<FieldInfo> iterator = list1.iterator();
				while (iterator.hasNext()) {
					if (!list2.contains(iterator.next()))
						iterator.remove();
				}
			}
		}
		return map1;
	}

}
